#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
const ll N=1e5+5;
vector<pair<ll,ll>> g[N];
ll K[N],dep[N],fa[N][21];
ll dis[N];
void dfs(ll u,ll Fa){
  dep[u]=dep[Fa]+1;
  fa[u][0]=Fa;
  for (ll i=1;i<=20;i++){
    fa[u][i]=fa[fa[u][i-1]][i-1];
  }
  for (auto son:g[u]){
    ll v=son.first,w=son.second;
    if (v!=Fa){
      dis[v]=dis[u]+w;
      dfs(v,u);
    }
  }
}
ll LCA(ll u,ll v){
  if (dep[u]<dep[v])swap(u,v);
  for (ll i=20;i>=0;--i){
    if (dep[fa[u][i]]>=dep[v]){
      u=fa[u][i];
    }
  }
  if (u==v)return u;
  for (ll i=20;i>=0;i--){
    if (fa[u][i]!=fa[v][i]){
      u=fa[u][i];
      v=fa[v][i];
    }
  }
  return fa[u][0];
}
ll path_dis(ll u,ll v){
  if (!u || !v)return 0;
  return dis[u]+dis[v]-2*dis[LCA(u,v)];
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  cin>>n>>k;
  for (ll i=1;i<n;i++){
    ll a,b,c;cin>>a>>b>>c;
    g[a].push_back({b,c});
    g[b].push_back({a,c});
  }
  dfs(1,0);
  ll ans=0;
  for (ll i=1;i<=k;i++){
    cin>>K[i];
    ans+=path_dis(K[i],K[i-1]);
  }
  for(ll i=1;i<=k;i++){
    cout<<ans-path_dis(K[i-1],K[i])-path_dis(K[i],K[i+1])+path_dis(K[i-1],K[i+1])<<" ";
  }
  
	return 0;
} 
